package utils

import (
	"bytes"
	"encoding/binary"
	"fmt"
	"os"
	"runtime/debug"
)

func Fatal(v any){
	fmt.Printf("rvld: \033[0;1;31mfatal:\033[0m %v\n",v)
	debug.PrintStack()
	os.Exit(1)
}

func MustErr(err error){
	if err != nil{
		Fatal(err)
	}
}

func Assert(condition bool){
	if !condition{
		Fatal("assert failed")
	}
}

func Read[T any](data []byte)(val T){
	reader := bytes.NewReader(data)
	err := binary.Read(reader,binary.LittleEndian,&val)
	MustErr(err)
	return
}